#include "pluginsmanagerpoolservice.h"

PluginsManagerPoolService::PluginsManagerPoolService()
{

}

/* 通过id查找插件 */
PluginsManagerPool *PluginsManagerPoolService::findPluginsManagerPoolById(const quint32 &id)
{
	return pmpd.findOne(id);
}

/* 通过插件管理器查找插件 */
QList<Plugin> PluginsManagerPoolService::findAllPluginByPluginsManager(const PluginsManager &pluginsManager)
{
	Specification spec;
	spec.setSqlWhere(
				Specification::equal(
					"pmid",
					QString::number(pluginsManager.getId())
					)
				);

	QList<PluginsManagerPool> list = pmpd.findAll(spec);
	QList<Plugin> res;

	foreach (PluginsManagerPool pluginsManager, list) {
		Plugin *plugin = pd.findOne(pluginsManager.getPid());
		res.append(*plugin);
	}

	return res;
}

/* 查找加载该插件的所有插件管理器 */
QList<PluginsManager> PluginsManagerPoolService::findAllPluginsManagerByPlugin(const Plugin &plugin)
{
	Specification spec;
	spec.setSqlWhere(
				Specification::equal(
					"pid",
					QString::number(plugin.getId()))
				);

	QList<PluginsManagerPool> list = pmpd.findAll(spec);
	QList<PluginsManager> res;

	foreach (PluginsManagerPool pluginsManagerPool, list) {
		PluginsManager *pluginsManager = pmd.findOne(pluginsManagerPool.getPmid());
		res.append(*pluginsManager);
	}

	return res;
}
